package main

import(
	"fmt"
	"net"
	"project06/common/message"
	"project06/server/control"
	"project06/server/utils"
	"io"

)
type Process struct{
	Conn net.Conn
}

func (this *Process)serviceProcess(mes *message.Message) (err error){
	
	switch mes.Type{
		case message.LoginMesType:
			//走登录逻辑
			up:=&control.Control{
				Conn:this.Conn,
			}
			err=up.ServiceLoginProcess(mes)
		case message.RegisterMesType:
			//走注册逻辑
			up:=&control.Control{
				Conn:this.Conn,
			}
			err=up.ServiceRegisterProcess(mes)
		case message.SmsMesType:
			//走注册逻辑
			mC:=&control.MessageControl{}
			mC.ServiceSmsMesProcess(mes)
		default:
			fmt.Println("类型不对,mes.Type=",mes.Type)
			
	}
	return
}

func (this *Process) Processor2() (errs error){
	for{
		tf:=&utils.Transfer{
			Conn:this.Conn,
		}
		mes,errs:=tf.ReadPkg()
		if errs !=nil{
			if errs ==io.EOF{
				fmt.Println("客户端退出，服务器端也退出..")
				return errs
			}else{
				fmt.Println("readPkg(conn) err",errs)
				return errs
			}
			
		}
		//fmt.Println("接收到的mes=",mes)
		errs=this.serviceProcess(&mes)
		if errs !=nil{
			fmt.Println("serviceProcess err",errs)
			return errs
		}
		//return 
		
		

	}
}